#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
	cout << "Wait creating namedPipe\n\n";
	WaitNamedPipe("\\\\.\\pipe\\pipeTest", NMPWAIT_WAIT_FOREVER);
	cout << "Create namedPipe\n\n";


	HANDLE hFile = CreateFile("\\\\.\\pipe\\pipeTest", GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
	cout << "Client : file is created\n";

	while(1){

		char buffer[255];
		cout << "Enter message for server : ";
		cin.getline(buffer, 80);
		DWORD size;

		if(WriteFile(hFile, buffer, strlen(buffer) + 1, &size, NULL))
			cout<<"Buffer is writed!!!\n\n";
		else{
			cout << GetLastError() << endl;
			cout << "size = " << size << endl;
		}

		cout << "Wait message from server..........\n";
		if(ReadFile(hFile, buffer, 255, &size, NULL))
		{
			cout<<"Read buffer!!!\n\n";
			cout<<"Buffer : " << buffer <<endl;
		}
	}
	return 0;
}